// let rs = require('readline-sync')
import { question } from "readline-sync";
import { Poker } from "./pokerts";
import { Card } from "./cardts"

let mapPrize:Map<string,number> = new Map()
mapPrize.set('同花顺', 100)
mapPrize.set('四条', 25)
mapPrize.set('满堂红', 10)
mapPrize.set('同花', 5)
mapPrize.set('顺子', 4)
mapPrize.set('三条', 3)
mapPrize.set('两对', 2)
mapPrize.set('一对', -1)
mapPrize.set('无对', -2)

let poker:Poker = new Poker()

let score:number = 100
while (true) {
  let bet_times:number = question('please give your bet')
  score = score - bet_times
  console.log(`your current score is ${score}`);
  let one_hand = poker.get_one_hand()
  poker.output_onehand(one_hand)
  let swap_cards:string = question('\nplease input card no what you want to change(1-5) input 0 to exit, input enter if you do not want to change any card,split by space\n')

  if (swap_cards === '0') {
    console.log('game over');
    break
  }
  if (swap_cards.length !== 0) {
    let swap_cards_arr:string[] = swap_cards.split(' ')
    let begin_index = 5;
    for (let card_index of swap_cards_arr) {
        let from_index = parseInt(card_index)-1
    //   card_index--
      one_hand.splice(card_index, 1, poker.get_one_card(begin_index++))
    }
  }
  poker.output_onehand(one_hand)
  let card_type:string = poker.get_type(one_hand)
  console.log(card_type);
  let tmp_score:number|undefined = mapPrize.get(card_type)
  if(tmp_score!==undefined){
  console.log(tmp_score*bet_times);
  score += tmp_score*bet_times;
}
}
